package Streamer;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import javax.swing.JFrame;
import javax.swing.JOptionPane;


public class UDPClient extends Thread
{

	private String serverAddress;
	private int serverPort;
	boolean keepRunning = true;
	
	DatagramSocket serverSocket;
	byte[] data = new byte[1024];
	byte[] buffer = new byte[1024];
	
	public UDPClient(String serverAddress, int serverPort) throws Exception
	{
		this.serverAddress = serverAddress;
		this.serverPort = serverPort;
		this.serverSocket = new DatagramSocket();
	}
	
	public void run()
	{
		while(keepRunning)
		{
			try 
			{
				data = "T 10.16.99.136:55751 -> 69.171.235.16:80 [AP]\n  GET /ping?partition=236&cb=gks9 HTTP/1.1..Host: 3-pct.channel.facebook.com..Connection: keep-alive..User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/".getBytes();
				DatagramPacket sendPacket = new DatagramPacket(data, data.length, InetAddress.getByName(serverAddress), serverPort);
				serverSocket.send(sendPacket);
				Thread.sleep(10L);
			} 
			
			 catch (Exception e) 
			{
				 JOptionPane.showMessageDialog(new JFrame(),e.getMessage());
			}
		}
	}

	public void stopThread() 
	{
		this.keepRunning = false;
		this.serverSocket.close();
	}
}